#include "fonctions_player.h"
#include "constantes_player.h"

bool validPoint(point p, int maxX, int maxY, int minX, int minY)
{
	return (p.x >= minX && p.x <= maxX) && (p.y >= minY && p.y <= maxY);
}
int movePoint(point *p, int dx, int dy)
{
	p->x += dx;
	p->y += dy;
	if (validPoint(*p,FIGHT_MAX_X,FIGHT_MAX_Y,FIGHT_MIN_X,FIGHT_MIN_Y))
		return 0;
	else
		return 1;
}

bool validSize(size s, int maxX, int maxY, int minX, int minY)
{
	return (s.height >= minX && s.height <= maxX) && (s.width >= minY && s.width <= maxY);
}
int reSize(size *s, int dh, int dw)
{
	s->height += dh;
	s->width += dw;
	if (validSize(*s,FIGHT_MAX_X,FIGHT_MAX_Y,FIGHT_MIN_X,FIGHT_MIN_Y))
		return 0;
	else
		return 1;
}

bool validRectangle(rectangle r, int maxX, int maxY, int minX, int minY)
{
	return movePoint(&(r.point), r.size.height, r.size.width) == 0 && r.size.height != 0 && r.size.width != 0;
}
int moveRectangle(rectangle *r, int dx, int dy)
{
	r->point.x += dx;
	r->point.y += dy;
	if (validRectangle(*r,FIGHT_MAX_X,FIGHT_MAX_Y,FIGHT_MIN_X,FIGHT_MIN_Y))
		return 0;
	else
		return 1;
}
int resizeRectangle(rectangle *r, int dh, int dw)
{
	r->size.height += dh;
	r->size.width += dw;
	if (validRectangle(*r,FIGHT_MAX_X,FIGHT_MAX_Y,FIGHT_MIN_X,FIGHT_MIN_Y))
		return 0;
	else
		return 1;
}
bool pointInRectangle(rectangle r, point p)
{
	return ((p.x >= r.point.x) && (p.x <= r.point.x + r.size.width)) && ((p.y >= r.point.y) && (p.x <= r.point.y + r.size.height));
}
bool superpositionRectangle(rectangle r1, rectangle r2)
{
	bool flag = false;
	flag |= pointInRectangle(r1,r2.point);
	r2.point.x += r2.size.width;
	flag |= pointInRectangle(r1,r2.point);
	r2.point.y += r2.size.height;
	r2.point.x -= r2.size.width;
	flag |= pointInRectangle(r1,r2.point);
	r2.point.x += r2.size.width;
	flag |= pointInRectangle(r1,r2.point);
	r2.point.y -= r2.size.height;
	r2.point.x -= r2.size.width;

	r1.point.x += r1.size.width;
	flag |= pointInRectangle(r2,r1.point);
	r1.point.y += r1.size.height;
	r1.point.x -= r1.size.width;
	flag |= pointInRectangle(r2,r1.point);
	r1.point.x += r1.size.width;
	flag |= pointInRectangle(r2,r1.point);
	r1.point.y -= r1.size.height;
	r1.point.x -= r1.size.width;
	return flag;
}